home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1994 November / Cd Ware (Nro. 2) - Epimundo.iso / DOS / PG / OOLIFE.ZIP / TEST.CPP < prev   
Encoding:
C/C++ Source or Header  |  1994-05-09  |  2.2 KB  |  86 lines

  1. #include "ca.h"
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <dos.h>
  6. #include <time.h>
  7. #include <iostream.h>
  8. #include <graphics.h>
  9. #include <alloc.h>
  10. //defines the number of cells on a side.  main will create a square
  11. //NOTE that DOS's goofy memory barrier prevents us from going
  12. //with very large life simulations.  The development machine
  13. //has 620K of free base and cannot support a larger array
  14. //than 45.
  15.  
  16. #define CELLS 45
  17.  
  18. int    GraphDriver;        /* The Graphics device driver        */
  19. int    GraphMode;           /* The Graphics mode value        */
  20. double AspectRatio;        /* Aspect ratio of a pixel on the screen*/
  21. int    MaxX, MaxY;        /* The maximum resolution of the screen */
  22. int    MaxColors;           /* The maximum # of colors available    */
  23. int    ErrorCode;           /* Reports any graphics errors        */
  24. struct palettetype palette;        /* Used to read palette info    */
  25.  
  26. void GraphInit();
  27.  
  28. main()
  29. {
  30.     CLife *life;
  31.     CLifeList lifeList;
  32.     long counter, totalCells = CELLS * CELLS;
  33.  
  34.     srand( (unsigned)time( NULL ) );
  35.     for(counter = 0; counter < totalCells; counter++)    //create the cells
  36.         {
  37.         life = new CLife;
  38.         if(rand()%100>50)            //Create a random startup
  39.             life->setLife(TRUE);
  40.         CGraphic *graphic = new CGraphic(counter / CELLS, counter % CELLS);
  41.         life->setGraphic(graphic);
  42.         lifeList.addLife(life);
  43.         }
  44.  
  45.     //Now tell the cells who their neighbors are
  46.     lifeList.associateCells();
  47.     lifeList.update();
  48.     lifeList.dirty();
  49.  
  50.     GraphInit();
  51.  
  52.     while(TRUE)
  53.         {
  54.         lifeList.cycle();
  55.         lifeList.update();
  56.         //sleep(1);
  57.         if(kbhit())
  58.             exit(0);
  59.         }
  60. }
  61.  
  62. void
  63. GraphInit()
  64. {
  65.     GraphDriver = DETECT;               /* Request auto-detection    */
  66.  
  67.     initgraph( &GraphDriver, &GraphMode, "" );
  68.     printf(" Graphics System Error: %s\n", grapherrormsg( graphresult()) );
  69.  
  70.     setgraphmode( GraphMode );
  71.     ErrorCode = graphresult();           /* Read result of initialization*/
  72.  
  73.     if( ErrorCode != grOk )          /* Error occured during init    */
  74.         {
  75.         printf(" Graphics System Error: %s\n", grapherrormsg( ErrorCode ) );
  76.         exit( 1 );
  77.         }
  78.  
  79.     getpalette( &palette );              /* Read the palette from board    */
  80.     MaxColors = getmaxcolor() + 1;    /* Read maximum number of colors*/
  81.  
  82.     MaxX = getmaxx();
  83.     MaxY = getmaxy();                     /* Read size of screen */
  84. }
  85.  
  86.